var config = require("core/config");
var host = config.host;

var order = host + "/order";

var baseUrl = order + "/base";
var handleUrl = order + "/handle";
var imgMax = 3;

module.exports.url = {
	base : {
		sellerPage : baseUrl + "/sellerPage",
		page : baseUrl + "/page",
		waitPayPage : baseUrl + "/waitPayPage",
		waitSendPage : baseUrl + "/waitSendPage",
		waitReceiptPage : baseUrl + "/waitReceiptPage",
		waitRefundPage : baseUrl + "/waitRefundPage",
		detail : baseUrl + "/detail",
		addMallOrder : baseUrl + "/addMallOrder",
		sellDetail: baseUrl + "/sellDetail",
		buyerTypeCount: baseUrl + "/buyerTypeCount",
		deliveryPage : baseUrl + "/deliveryPage",
		deliveryDetail : baseUrl + "/deliveryDetail",
		changeDeliveryUserId : baseUrl + "/changeDeliveryUserId",
		shopOrderPage : baseUrl + "/shopOrderPage",
		shopOrderDetail : baseUrl + "/shopOrderDetail",
		shopOrderCount: baseUrl + "/shopOrderCount",
		shopOrderUncomplated: baseUrl + "/shopOrderUncomplated",
		myOrderCount: baseUrl + "/myOrderCount",
		myCouponCount: baseUrl + "/myCouponCount",
		detailByOrderNo:baseUrl + "/detailByOrderNo",
		orderSuccess:baseUrl + "/orderSuccess",
		scan2Finish:baseUrl + "/scan2Finish" //扫码完成自提订单
	},
	handle : {
		buyerCancel : handleUrl + "/buyerCancel",
		signed : handleUrl + "/signed",
		applyReturn : handleUrl + "/applyReturn",
		sended:handleUrl + "/sended",
		sellerCancel : handleUrl + "/sellerCancel",
		pickuped : handleUrl + "/pickuped",
		deliveryed : handleUrl + "/deliveryed",
		applyReturnPay : handleUrl + "/applyReturnPay",
		sellerAgreeReturnPay : handleUrl + "/sellerAgreeReturnPay",
		sellerRefuseReturnPay : handleUrl + "/sellerRefuseReturnPay"
	}
};

/**
 * ';'分隔图片字符串,转变成[{source:imgs[j],imgCount:""}]格式
 * 
 * @isShowAll:是否显示图片总数量，imgCount:共x张
 * @imgStr:img';'分隔图片字符串
 * @callback:回调函数
 */
var imgFormatFun = function(isShowAll, imgStr) {
	var imgs = imgStr.split(";");
	if (imgs.length > 0) {
		// 图片的数据
		var jsonImgs = [];
		var imgsL = imgs.length;
		if (imgsL >imgMax&&isShowAll) {
			imgsL = imgMax;
		}
		// 图片的数据
		for (var j = 0; j < imgsL; j++) {
			if (j == (imgsL - 1)&&isShowAll) {
				jsonImgs.push({
					source : imgs[j],
					imgCount : "共" + imgs.length + "张"
				});
			} else {
				jsonImgs.push({
					source : imgs[j],
					imgCount : ""
				});
			}
		}
		return jsonImgs;
	}
}
module.exports.fun = {
		img : {
			format : imgFormatFun
		}
};
